
var GRID_SIZE:number = 32;
var GRID_COLUMNS:number = 15;
var GRID_ROWS:number = 25;
var INITIAL_SPEED:number = 25;
var BASE_SCORE:number = 10;
var MAX_SCORE_FACTOR:number = 10;
var KEY_LEFT:string = "65";//a
var KEY_RIGHT:string = "68";//d
var KEY_DOWN:string = "83";//s
var KEY_DOWN_FAST:string = "74";//j
var KEY_CHANGE:string = "75";//j
var KEY_RESTART:string = "108";//enter


function init_conf(o:Object):void{
	if(o == null){
		return;
	}
	if(o["GRID_ROWS"] > 0){
		GRID_ROWS = o["GRID_ROWS"];
	}
	if(o["GRID_SIZE"] > 0){
		GRID_SIZE = o["GRID_SIZE"];
	}
	if(o["GRID_COLUMNS"] > 0){
		GRID_COLUMNS = o["GRID_COLUMNS"];
	}
	if(o["INITIAL_SPEED"] > 0){
		INITIAL_SPEED = o["INITIAL_SPEED"];
	}
	if(o["BASE_SCORE"] > 0){
		BASE_SCORE = o["BASE_SCORE"];
	}
	if(o["MAX_SCORE_FACTOR"] > 0){
		MAX_SCORE_FACTOR = o["MAX_SCORE_FACTOR"];
	}
	if(o["KEY_LEFT"] != null){
		KEY_LEFT = o["KEY_LEFT"];
	}
	if(o["KEY_RIGHT"] != null){
		KEY_RIGHT = o["KEY_RIGHT"];
	}
	if(o["KEY_DOWN"] != null){
		KEY_DOWN= o["KEY_DOWN"];
	}
	if(o["KEY_DOWN_FAST"] != null){
		KEY_DOWN_FAST = o["KEY_DOWN_FAST"];
	}
	if(o["KEY_CHANGE"] != null){
		KEY_CHANGE= o["KEY_CHANGE"];
	}
}

function getAddScore(level:number):number{
	return level * BASE_SCORE;
}

function getMaxScore(level:number):number{
	return level * MAX_SCORE_FACTOR  * BASE_SCORE;
}

function getSpeed(level:number):number{
	let speed:number = INITIAL_SPEED - 2*level;
	if(speed <= 0){
		speed = 1;
	}
	return speed;
}

function isPress(keyCode:number,keyType:string):boolean{
	return keyType.indexOf(""+keyCode) >= 0;
}

